package com.linqi.freebie.http.ktorClientCio.interceptor

import io.github.aakira.napier.Napier
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.statement.HttpResponse

class HeaderInterceptor(
    private val headersToAdd: Map<String, String> = emptyMap()
) : HttpInterceptor {

    override suspend fun onRequest(builder: HttpRequestBuilder) {
        try {
            for ((key, value) in headersToAdd) {
                builder.headers.append(key, value)
            }
            //Napier.d("HeaderInterceptor -> 添加请求头: $headersToAdd", tag = "HttpLog")
        } catch (e: Exception) {
            //Napier.e("HeaderInterceptor onRequest异常: ${e.message}", e, tag = "HttpLog")
        }
    }

    override suspend fun onResponse(response: HttpResponse) {
        // 如果你想响应时做点什么，也可以加代码，这里默认不处理
    }
}
